<%--
 *  File:    ChangeColumnCheck.jsp
 *  @Author: beliveli
 *  Date:    2013/10/24
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.OvalLabel" %>
<%@ page import="com.oval.util.OvalCustomColumn" %>
<%@ page import="com.oval.util.OvalCustomMessage" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>

<% 
	String strModuleName = "IMG";
	String privilegeCode = "IMG0303";
   String strTableName = "ovuser";
   String contextPath = request.getContextPath();
%>



<%
   Category cat = Category.getInstance("jsp.ChangeColumnCheck");
   HashMap mapUser = (HashMap)session.getAttribute("userinfo");
   if(mapUser == null)
   {
      mapUser = new HashMap();
   }
   
   String uploadconfigid = request.getParameter("uploadconfigid")+"";
   String uploadcolumncheckid = request.getParameter("uploadcolumncheckid")+"";
%>
<% //--------------------------------------  include files list --%>

<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<%@ include file="/inc/AlertError.inc" %>
<%@ include file="/inc/SummaryDivision.inc" %>
<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="p_changecolumncheck"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
</head>
<%
HashMap configcolumncheckhash = new HashMap(); 
if(pageContext.getAttribute("configcolumncheck") !=null){
	configcolumncheckhash = (HashMap)pageContext.getAttribute("configcolumncheck");
}
%>
<%@ include file="/inc/CheckPassword.inc" %>
<script language="JavaScript">
function conditionChange(){
	var value = cform.checkruleid.value;
	if (value == 3) {
		_back();
		cform.tablename.style.display="block";
		document.cform.columnname.style.display="block";
	   	document.cform.valuecolumns.style.display="block";
	   	document.cform.othercondition.style.display="block";
	   	
	   	document.cform.tablename.command="notnull";
	   	document.cform.tablename.label="<%= label.getLabelName("L_TableName") %>";
	   	
	   	document.cform.columnname.command="notnull";
	   	document.cform.columnname.label="<%= label.getLabelName("L_ContactColumn") %>";
	}else if (value == 5) {
		_back();
		document.cform.condition1.style.display="block";
		
		document.cform.condition1.command="notnull";
	   	document.cform.condition1.label="<%= label.getLabelName("L_SQL") %>";
	}else if (value == 2) {
		_back();
		//cform.tablename.style.display="block";
		cform.condition1.style.display="block";
		document.cform.columnname.style.display="block";
	   	document.cform.valuecolumns.style.display="block";
	   	
	   	document.cform.condition1.command="notnull";
	   	document.cform.condition1.label="<%= label.getLabelName("L_DicType") %>";
	   	
	   	document.cform.columnname.command="notnull";
	   	document.cform.columnname.label="<%= label.getLabelName("L_ContactColumn") %>";
	}else if (value == 4) {
		_back();
	   	document.cform.uploadcolumnconfigidOne.style.display="block";
			   	
	   	document.cform.uploadcolumnconfigidTwo.style.display="block";

	   	cform.uniquetablename.style.display="block";
	   	
	}else {
		_back();
	}
}

function _back() {
	document.cform.condition1.value="";	
	cform.tablename.style.display="none";
	cform.uniquetablename.style.display="none";
	cform.uploadcolumnconfigidOne.style.display="none";
	cform.uploadcolumnconfigidTwo.style.display="none";
	document.cform.columnname.style.display="none";
	document.cform.valuecolumns.style.display="none";
	document.cform.condition1.style.display="none";
	document.cform.othercondition.style.display="none";
	document.cform.valuecolumns.length=1;
	document.cform.columnname.length=1;
	forvaluecolumns = true;
	forcolumns = true;
	
	document.cform.condition1.command="";
	document.cform.condition1.label="";
	document.cform.columnname.command="";
	document.cform.columnname.label="";
}

var forvaluecolumns = true;
var forcolumns=true;

function cleancolumns(obj) {
	forvaluecolumns = true;
	forcolumns = true;
	document.cform.valuecolumns.length=1;
	document.cform.columnname.length=1;
	
	document.cform.condition1.value=obj.value;
}

function setconditionvalue(obj,type){
	if(obj.value == -1){
		eval("document.cform.condition"+type).value=" ";
	}else{
		eval("document.cform.condition"+type).value=obj.value;
	}
}

function getcolumns(){
	//alert("asd");
	if (!forcolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.columnname.length=1;
	  var  datahandler = new  DataHandler() ;
	  
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.columnname");
	  datahandler.runDataHandler();
	  
	  forcolumns = false;
}
function initgetcolumns(){
	if (!forcolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.columnname.length=1;
	  var  datahandler = new  DataHandler() ;
	  
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.columnname");
	  datahandler.add_function("initgetcolumns_back()") ;
	  datahandler.runDataHandler();
	  
	  forcolumns = false;
}

function initgetcolumns_back(){
	document.cform.columnname.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition2")) %>";
	initgetvaluecolumns(null);
}

function getvaluecolumns(){
	  if (!forvaluecolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.valuecolumns.length=1;
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.valuecolumns");
	  datahandler.runDataHandler();
	  
	  forvaluecolumns = false;
}

function initgetvaluecolumns(type){
	  if (!forvaluecolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.valuecolumns.length=1;
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.valuecolumns");
	  if(type == 2){
		  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.columnname");
	  }
	  
	  
	  datahandler.add_function("initgetvaluecolumns_back("+type+")") ;
	  datahandler.runDataHandler();
	  
	  forvaluecolumns = false;
}

function initgetvaluecolumns_back(type){
	if(type == 2){
		document.cform.valuecolumns.value="<%=JspHelper.filterNull(configcolumncheckhash.get("valuecolumn")) %>";
		document.cform.columnname.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition2")) %>";
	}else{
		document.cform.valuecolumns.value="<%=JspHelper.filterNull(configcolumncheckhash.get("valuecolumn")) %>";
		document.cform.othercondition.value="<%=JspHelper.filterNull(configcolumncheckhash.get("othercondition")) %>";
	}
}


function cleancolumnsnew(obj) {
	forvaluecolumns = true;
	forcolumns = true;
	if(obj.value == -1){
		document.cform.othercondition.value=" ";
	}else{
		document.cform.othercondition.value=obj.value;
	}
}

function page_done(){
	if(!checkForm(cform)) return;
    if (cform.checkruleid.value==2 || cform.checkruleid.value==3) {
    	document.cform.condition2.value=document.cform.columnname.value;
    	document.cform.valuecolumn.value=document.cform.valuecolumns.value;
    }
    //changedField();
    cform.actionname.value = "add";
    cform.target = "_parent";
    isRunning = true;
    cform.submit();
}


</script>
<script language="javascript" for="window" event="onload">
	if(document.readyState=="complete"){  
		conditionChange();
		var value = cform.checkruleid.value;
		if (value == 3) {
			document.cform.tablename.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition1")) %>";
			document.cform.condition1.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition1")) %>";
			initgetcolumns();
		}
		else if (value == 5) {
			document.cform.condition1.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition1")) %>";
		}else if (value == 2) {
			document.cform.condition1.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition1")) %>";
			initgetvaluecolumns(value)
		}else if (value == 4) {
		   	document.cform.uploadcolumnconfigidOne.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition1")) %>";
				   	
		   	document.cform.uploadcolumnconfigidTwo.value="<%=JspHelper.filterNull(configcolumncheckhash.get("condition2")) %>";
		   	document.cform.uniquetablename.value="<%=JspHelper.filterNull(configcolumncheckhash.get("othercondition")) %>";
		   	
		}/**else {
			_back();
		}*/
	}
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher" >
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr> 
    <td valign="top"> 
        <input type="hidden" name="pagename" value="p_changecolumncheck" >
        <input type="hidden" name="actionname" >
        <custom:hidden name="userinfo" property="orgid" scope="session" />
        <custom:hidden property="uploadconfigid" value="<%=uploadconfigid %>" />
        <custom:hidden property="uploadcolumncheckid" value="<%=uploadcolumncheckid %>" />
        <input type="hidden" name="languagecode" value="<%= strLanguageCode %>" >
        
        
        <table width="100%" border="1" cellpadding="2" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
          <tr> 
            <td class="need" width="95"><%= label.getLabelName("L_SortNo") %><%= label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:text property="columnno" name="configcolumncheck"  />
            </td>
            <td class="need" width="95"><%= label.getLabelName("L_RowName") %><%= label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:select optionsName="checkcolumninfo" name="configcolumncheck" property="uploadcolumnconfigid" optionInnerTextKey="columnname" optionValueKey="uploadcolumnconfigid" defaultValue="---------"  command="notnull" label="L_RowName"/>
            </td>
            <td class="need" width="95"><%= label.getLabelName("L_CheckRule") %><%= label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:selectdic name="configcolumncheck" property="checkruleid" dictType="columncheckrule" defaultValueCost="" defaultValue="---------" onchange="conditionChange();" command="notnull" label="L_CheckRule"/>
            </td>
          </tr>
          <tr> 
            <td class="td-text" width="95"><%= label.getLabelName("L_Condition") %>1<%= label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:select optionsName="alltables" name="configcolumncheck" property="tablename" optionInnerTextKey="tablename" optionValueKey="tablename" defaultValue="---------"  style="display:none" onchange="cleancolumns(this)"/>
                <input type="text" name="condition1" style="display: none" size="35"/>
            	<custom:select optionsName="allcolumns" name="configcolumncheck" property="uploadcolumnconfigidOne" optionInnerTextKey="columnname" optionValueKey="columnname" defaultValue="---------"  style="display:none" onchange="setconditionvalue(this,1)" />
			</td>
            <td class="td-text" width="95"><%= label.getLabelName("L_Condition") %>2<%= label.getLabelName("L_Colon") %></td>
            <td>
				<custom:select name="configcolumncheck" property="columnname" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" style="display:none" onclick="getcolumns()"/>
                <input type="text" name="condition2" style="display: none"/>
                <custom:select optionsName="allcolumns" name="configcolumncheck" property="uploadcolumnconfigidTwo" optionInnerTextKey="columnname" optionValueKey="columnname" defaultValue="---------"  style="display:none" onchange="setconditionvalue(this,2)" />
			</td>
            <td class="td-text" width="95"><%= label.getLabelName("L_Value") %><%= label.getLabelName("L_Field") %></td>
            <td>
				<custom:select name="configcolumncheck" property="valuecolumns" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" style="display:none"  onclick="getvaluecolumns()"/>
                <input type="text" name="valuecolumn" style="display: none"/>
			</td>
          </tr>
          <tr> 
            <td class="td-text" width="95"><%= label.getLabelName("L_Other") %><%= label.getLabelName("L_Condition") %></td>
            <td colspan="5">
				<input type="text" name="othercondition"  style="display: none" />
                <custom:select optionsName="alltables" name="configcolumncheck" property="uniquetablename" optionInnerTextKey="tablename" optionValueKey="tablename" defaultValue="---------"  style="display:none" onchange="cleancolumnsnew(this)"/>
			</td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="summary_top" ></td>
          </tr>
          <tr> 
            <td class="td_center"> <a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
          </tr>
        </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>